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.
- 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.
- Java 17
- Spring Boot 3.5.11
- Spring Data JPA
- H2 Database (In-memory for development)
- Lombok (Boilerplate reduction)
- Maven (Dependency management)
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
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
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
}The shipping charge is calculated using the following rules:
- Base Distance: Distance is calculated from the Nearest Warehouse (to the seller) to the Customer's Location.
-
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$ )
-
0 - 100 km: MiniVan (
- Fixed Costs: A standard base charge of $10 is added to every shipment.
-
Express Delivery: If selected, an additional charge of
$1.2 \times weight$ is applied.
-
Clone the repository:
git clone https://github.com/Samearth17/Shipping-and-Logistics-Backend-Service.git cd shipping -
Build the project:
./mvnw clean install
-
Run the application:
./mvnw spring-boot:run
-
Access H2 Console (Optional): Available at
http://localhost:8080/h2-console(if enabled in properties).