Service
The Service is the core component of the VRP (Vehicle Routing Problem) system, managing various operations such as creating, updating, retrieving, and deleting objects like customers, vehicles, orders, territories, and miscellaneous locations. It also handles routes optimization, ensuring efficient deliveries and pickups. The Service class acts as a bridge between the backend system and users by handling asynchronous operations through listeners.
This documentation provides an in-depth explanation of the Service class, how it works, and example usage.
How Service Works
The Service class provides API endpoints for interacting with different objects in the VRP system. Operations execute asynchronously, requiring a ProgressListener to track execution status and completion.
Key Functionalities
- Customer Management: Manage customers by adding, updating, retrieving, and deleting them.
- Order Processing: Manage orders, including creation, retrieval, updates, and prioritization.
- Miscellaneous Locations: Handle depots and custom locations. See Miscellaneous Locations.
- Vehicle Management: Manage vehicles with attributes like type, capacity, and availability.
- Territory Management: Define and modify territories for better operational control.
- Optimizations: Optimize routes considering vehicle capacities, service times, and order constraints. See Optimization.
- Routes: Managing and optimizing routes within a Vehicle Routing Problem (VRP). See Routes.
- Fuel Prices: Manage fuel prices for different fuel types within the VRP system. See Fuel Prices.
- Data Cleanup: Remove outdated or unnecessary data.
Each function follows an asynchronous execution pattern, requiring a listener to track progress and completion.
Progress Listener
The ProgressListener is a crucial component for tracking the progress and completion of asynchronous operations. It provides notifications when an operation starts, progresses, or finishes.
Example
Service Operations
Creating an Object
All objects such as customers, vehicles, orders, and territories must be created before use.
Example Adding a Customer
If the operation is successful, the customer will have an id assigned; which can be retrieved using the method customer.getId().
How it works
- Create a
vrp::Customerand set the desired fields. - Create a
ProgressListenerandvrp::Service. - Call the
addCustomer()method from thevrp::Serviceusing thevrp::CustomerandProgressListenerand wait for the operation to be done.
Retrieving Objects
Get a Specific Request
Example Get a Vehicle by ID
How it works
- Create a
ProgressListener, avrp::Serviceand avrp::Vehicle. - Call the
getVehicle()method from thevrp::Serviceusing thevrp::Vehiclefrom 1.), the ID of the vehicle that you want to retrieve and theProgressListener. - Once the operation completes, the
vrp::Vehiclefrom 1.) will be populated.
Example Get All Orders
Returns all the Orders of the API user. SearchTerm the parameter for general search across Orders.
How it works
- Create a
ProgressListenerandvrp::Serviceand avrp::OrderList. - Call the
getOrders()method from thevrp::Serviceand theProgressListener. - Once the operation completes, the list from 1.) will be populated with orders that match the search criteria.
Updating Objects
Example Updating an Territory
Territories can be updated with new names, types, or geographical data.
If the shape or the size of the territory is updated, then the list of orders that are inside the territory was also updated. You can access it using the method territory.getOrders().
How it works
- Create a
ProgressListenerand avrp::Service. - Retrieve the territory you want to update (see Get Territory) example) in a
vrp::Territory. - Change the desired fields of the
vrp::Territory. - Call the
updateTerritory()method from thevrp::Serviceusing thevrp::Territoryfrom 2.) and theProgressListenerand wait for the operation to be done.
Deleting Objects
Objects can be removed individually or in bulk.
Example Delete Route
Delete the routes from the list. Routes can be deleted individually or in bulk.
The orders of a deleted route will also be deleted from the optimization to which the route belongs (excepting the orders that are also used in other routes of the same optimization, such as depots). If the route is the only route of an optimization, then it cannot be deleted, instead delete the optimization (see Delete Optimization).
How it works
- Create a
ProgressListenerandvrp::Service. - Call the
deleteRoute()method from thevrp::Serviceusing the routes' IDs andProgressListenerand wait for the operation to be done.
Cleaning All Data
The clean operation deletes all the date saved for an user.
Example Cleaning All Data
Advanced Operations
This section covers advanced functionalities that allow users to perform complex operations such as retrieving customer order history, merging or unlinking routes, generating territories, and retrieving territory-specific orders. Each operation is designed to optimize workflows and improve efficiency.
Retrieving Customer Order History
Purpose: This operation allows you to retrieve the order history of a specific customer, including details about the optimizations and routes associated with their orders.
Use Case:
- Dividing a city into neighborhoods (one territory for each neighborhood) then creating an optimization using the commands in each territory.
How It Works:
The system queries the database for all orders placed by the customer and returns information about the optimizations and routes involved. This helps in understanding customer patterns and improving service delivery.
Important Notes:
- Ensure the customer ID is valid and accessible.
For a detailed step-by-step guide, refer to Retrieving Customer Order History.
Merging Routes
Purpose: Combine multiple routes into a single, unified route.
Use Case:
- Consolidate routes for better resource utilization.
- Simplify route management by reducing the number of active routes.
How It Works:
- Select multiple routes to merge.
- A new optimization is created for the merged route, inheriting configuration parameters, vehicle constraints, and other fields from the first route in the list.
- The merged route is not automatically optimized after creation.
Important Notes:
- The merged route retains the properties of the first route in the list.
- Orders from the merged routes are combined into the new route.
For a detailed step-by-step guide, refer to Merging Routes.
Unlinking Routes
Purpose: Remove a route from its associated optimization, making it independent.
Use Case:
- Separate a route for individual management or re-optimization.
- Remove a route from an optimization without deleting its orders.
How It Works:
- The selected route is unlinked from its optimization.
- A new optimization is created for the unlinked route, preserving its original configuration parameters, vehicle constraints, and other fields.
- Orders from the unlinked route are removed from the original optimization.
Important Notes:
- The unlinked route becomes a standalone entity.
- The new optimization can be modified or re-optimized as needed.
For a detailed step-by-step guide, refer to Unlink Routes.
Generating Territories
Purpose: Automatically create territories based on a set of geographic coordinates.
Use Case:
- Divide a large area into smaller, manageable territories for efficient order management.
- Assign orders to specific territories for better organization.
How It Works:
- Use the generateTerritories method to create territories.
- Provide a set of coordinates (minimum 3 coordinates per territory).
- If the number of territories is not specified, the algorithm determines the optimal number based on the input data.
Important Notes:
- At least 3 coordinates are required to generate a single territory.
- The number of coordinates should be at least 3 times the number of territories to be created.
For a detailed step-by-step guide, refer to this Generate Territories.
Retrieving Territory Orders
Purpose: Fetch all orders assigned to a specific territory.
Use Case:
- View and manage orders within a specific geographic area.
- Analyze order distribution across territories.
How It Works:
- Use the getTerritoriesOrders function to retrieve orders.
- Provide the territory ID to fetch all orders located within that territory.
Important Notes:
- The function returns all orders associated with the specified territory ID.
- Ensure the territory ID is valid and corresponds to an existing territory.
For a detailed step-by-step guide, refer to this Retrieving Territory Orders.
Error Handling
| Error Code | Description | Solution |
| - | - | |
| KInvalidInput | Missing required fields or invalid data. | Ensure all fields are properly filled. |
| KNotFound | The specified object ID does not exist. | Verify the correct ID is used. |
| KInternalAbort | Server-side issue or unexpected error. | Retry the request or check system logs. |
Conclusion
The Service is a powerful tool for managing logistics operations, offering asynchronous execution and flexibility in handling various objects. Whether dealing with orders, customers, vehicles, or territories, this API ensures efficient and scalable interactions.
For more details, refer to the linked object documentation: