Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Shipping & Logistics Service

A Spring Boot-based backend service designed to optimize logistics by finding the nearest warehouses and calculating precise shipping charges based on distance, weight, and delivery priority.

Features

  • Nearest Warehouse Discovery: Automatically finds the most optimal warehouse for a seller based on geographical coordinates.
  • Dynamic Shipping Calculation: Calculates shipping costs using a slab-based pricing model and transport mode selection.
  • Support for Express Delivery: Premium delivery options with weight-based surcharges.
  • Geospatial Logic: Uses Haversine distance calculation for accurate logistics planning.

Tech Stack

  • Java 17
  • Spring Boot 3.5.11
  • Spring Data JPA
  • H2 Database (In-memory for development)
  • Lombok (Boilerplate reduction)
  • Maven (Dependency management)

Project Structure

com.jumbotail.shipping
├── controller   # REST API Endpoints
├── entity       # JPA Entities (Customer, Seller, Warehouse, Product)
├── repository   # Data Access Layer
├── service      # Business Logic (Shipping calculation)
├── util         # Helpers (Distance calculation)
└── ShippingApplication.java

API Documentation

1. Find Nearest Warehouse

Returns the warehouse closest to the specified seller.

  • URL: /api/v1/warehouse/nearest
  • Method: GET
  • Query Params: sellerId (Long)

Example Request: GET http://localhost:8080/api/v1/warehouse/nearest?sellerId=1


2. Calculate Shipping Charge

Calculates the final shipping cost for a product delivery.

  • URL: /api/v1/shipping-charge/calculate
  • Method: POST
  • Payload:
    {
      "sellerId": 1,
      "customerId": 101,
      "deliverySpeed": "express"
    }

Example Response:

{
  "shippingCharge": 450.75
}

⚖️ Shipping Logic

The shipping charge is calculated using the following rules:

  1. Base Distance: Distance is calculated from the Nearest Warehouse (to the seller) to the Customer's Location.
  2. Transport Slab:
    • 0 - 100 km: MiniVan ($3 \times distance \times weight$)
    • 101 - 500 km: Truck ($2 \times distance \times weight$)
    • > 500 km: Aeroplane ($1 \times distance \times weight$)
  3. Fixed Costs: A standard base charge of $10 is added to every shipment.
  4. Express Delivery: If selected, an additional charge of $1.2 \times weight$ is applied.

⚙️ Setup & Installation

  1. Clone the repository:

    git clone https://github.com/Samearth17/Shipping-and-Logistics-Backend-Service.git
    cd shipping
  2. Build the project:

    ./mvnw clean install
  3. Run the application:

    ./mvnw spring-boot:run
  4. Access H2 Console (Optional): Available at http://localhost:8080/h2-console (if enabled in properties).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages