A Spring Boot application that optimizes the allocation of delivery orders to a fleet of vehicles based on their locations, capacity, and priority.
- Haversine Distance Calculation: Accurately calculates distances between coordinates.
- Optimized Dispatch: Assigns orders based on:
- Priority (High > Medium > Low)
- Vehicle Capacity
- Minimum accumulated travel distance (Greedy approach)
- REST API: Endpoints to input orders, vehicles, and retrieve the dispatch plan.
- In-Memory Database: H2 database for easy setup and testing.
- Java 17 or higher
- Maven 3.6+
- Clone the repository (if applicable)
- Build the project:
mvn clean install
- Run the application:
The application will start on
mvn spring-boot:run
http://localhost:8080.
Endpoint: POST /api/dispatch/orders
Body:
{
"orders": [
{
"orderId": "ORD001",
"latitude": 12.9716,
"longitude": 77.5946,
"address": "MG Road, Bangalore",
"packageWeight": 10,
"priority": "HIGH"
}
]
}Endpoint: POST /api/dispatch/vehicles
Body:
{
"vehicles": [
{
"vehicleId": "VEH001",
"capacity": 100,
"currentLatitude": 12.9716,
"currentLongitude": 77.6413,
"currentAddress": "Indiranagar, Bangalore"
}
]
}Endpoint: GET /api/dispatch/plan
Response:
{
"dispatchPlan": [
{
"vehicleId": "VEH001",
"totalLoad": 10.0,
"totalDistance": "5.20 km",
"assignedOrders": [ ... ]
}
]
}Access the H2 database console at: http://localhost:8080/h2-console
- JDBC URL:
jdbc:h2:mem:testdb - User:
sa - Password:
password