Orders
The Order class provides functionalities for managing orders within the VRP system. An order represents a pickup or delivery request and contains information such as location, customer details, time constraints, and priority settings. The API allows users to:
- Create new orders with relevant details.
- Retrieve existing orders by ID or list all orders.
- Update order information such as address, time window, or priority.
- Delete orders when no longer needed.
Order Structure
Each order object consists of the following attributes:
| Name | Type | Description | Setter | Getter |
|---|---|---|---|---|
| Id | LargeInteger | Unique identifier for the order. | ❌ | ✅ |
| Coordinates | Coordinates | Geographical coordinates of the order. | ✅ | ✅ |
| Address | AddressInfo | Address information of the order. | ✅ | ✅ |
| Customer | ICustomer | Customer who placed the order. | ✅ | ✅ |
| Alias | String | Alias name of the order. | ✅ | ✅ |
| FirstName | String | First name associated with the order. | ✅ | ✅ |
| LastName | String | Last name associated with the order. | ✅ | ✅ |
| PhoneNumber | String | Phone number associated with the order. | ✅ | ✅ |
| Type | EOrderType | Type of the order. | ✅ | ✅ |
| TimeWindow | std::pair<const Time*, const Time*> | Time window for delivery or pickup. | ✅ | ✅ |
| ServiceTime | unsigned int | Service time at the delivery or pickup location (in seconds). | ✅ | ✅ |
| NumberOfPackages | unsigned int | Number of packages to be delivered or picked up. | ✅ | ✅ |
| Weight | float | Weight of the goods to be delivered or picked up. | ✅ | ✅ |
| Cube | float | Cubic volume of the goods to be delivered or picked up. | ✅ | ✅ |
| Revenue | float | Revenue associated with the order. | ✅ | ✅ |
| Priority | EOrderPriority | Priority of the order. | ✅ | ✅ |
| Status | EOrderStatus | Status of the order. | ❌ | ✅ |
| State | EOrderState | State of the order. | ❌ | ✅ |
| CreationTime | Time | Creation time of the order. | ❌ | ✅ |
| DepotId | LargeInteger | Depot ID to which the order belongs. | ✅ | ✅ |
| CustomData | CustomDataList | Custom data associated with the order. | ✅ | ✅ |
Managing Orders
Creating an Order
Orders must be created before they can be processed in optimizations.
If the operation is successful, the order will have an id assigned; which can be retrieved using the method order.getId(), if not, an error code is returned which can be interpreted as mentioned at the end of the page.
How it works
- Create a
vrp::Orderand set the desired fields. - Create a
ProgressListenerandvrp::Service. - Call the
addOrder()method from thevrp::Serviceusing thevrp::OrderandProgressListenerand wait for the operation to be done.
Example
Retrieving Orders
There are two ways to retrieve order data:
a) Get an Order by ID
Get a certain Order by ID.
How it works
- Create a
ProgressListener, avrp::Serviceand avrp::Order. - Call the
getOrder()method from thevrp::Serviceusing thevrp::Orderfrom 1.), the ID of the order that you want to retrieve and theProgressListener. - Once the operation completes, the
vrp::Orderfrom 1.) will be populated.
b) Get All Orders (with optional filtering)
Returns all orders of the API user (which contain the search term).
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 an Order
Saves the updates made to a order. Orders can be updated with new addresses, contact details, or other relevant information.
Once an order is created, the customer associated with the order cannot be changed.
How it works
- Create a
ProgressListenerand avrp::Service. - Retrieve the order you want to update (see Get Order) in a
vrp::Order. - Change the desired fields of the
vrp::Order. - Call the
updateOrder()method from thevrp::Serviceusing thevrp::Orderfrom 2.) andProgressListenerand wait for the operation to be done.
Example
Deleting an Order
Orders can be deleted individually or in bulk.
How it works
- Create a
ProgressListenerandvrp::Service. - Call the
deleteOrder()method from thevrp::Serviceusing the order object andProgressListenerand wait for the operation to be done.
When orders are deleted, they will also be removed from any optimizations they were used in.
Error Handling
The API provides specific error codes to identify potential issues. Below is a summary of common errors and their solutions:
| Error Code | Description | Solution |
||-|-|
| KInvalidInput | Missing required fields or invalid data. | Ensure all mandatory fields are filled. |
| KNotFound | The specified order ID does not exist. | Verify that the correct order ID is used. |
| KInternalAbort | Server-side issue or unexpected error. | Retry the request or check API status. |