Customers
The Customer class is a core component of the Fleet Management SDK, allowing users to create, manage, and retrieve customer data. Customers represent entities that place orders and serve as primary points for delivery or pickup. Each customer has a unique identity and a defined location, ensuring accurate routing and logistics optimization.
Using this API, developers can:
- Add new customers to the system.
- Retrieve and update customer details such as address, contact information, and custom attributes.
- Delete customers when they are no longer needed.
- Access historical order data for a customer.
By integrating this API, businesses can streamline their customer management and optimize logistics operations effectively.
Customer Structure
Each customer object consists of the following attributes:
| Name | Type | Description | Setter | Getter |
|---|---|---|---|---|
| Id | LargeInteger | Unique identifier for the customer. | ❌ | ✅ |
| Coordinates | Coordinates | Coordinates representing the location of the customer. | ✅ | ✅ |
| Address | AddressInfo | Address information of the customer. | ✅ | ✅ |
| Alias | String | Alias name for the customer. | ✅ | ✅ |
| FirstName | String | First name of the customer. | ✅ | ✅ |
| LastName | String | Last name of the customer. | ✅ | ✅ |
String | Email address of the customer. | ✅ | ✅ | |
| PhoneNumber | String | Phone number of the customer. | ✅ | ✅ |
| CustomData | CustomDataList | Custom data associated with the customer. | ✅ | ✅ |
Managing Customers
Creating a Customer
Add a customer to the agenda to create orders for this customer and to use them in optimizations.
If the operation is successful, the customer will have an id assigned; which can be retrieved using the method customer.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::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.
Example
Retrieving Customers
There are two ways to retrieve customer data:
a) Get a Customer by ID
Get a certain Customer by ID.
How it works
- Create a
ProgressListener, avrp::Serviceand avrp::Customer. - Call the
getCustomer()method from thevrp::Serviceusing thevrp::Customerfrom 1.), the ID of the customer that you want to retrieve and theProgressListener. - Once the operation completes, the
vrp::Customerfrom 1.) will be populated.
b) Get All Customers (with optional filtering)
Returns all customers of the API user (which contain the search term).
How it works
- Create a
ProgressListenerandvrp::Serviceand avrp::CustomerList. - Call the
getCustomers()method from thevrp::Serviceand theProgressListener. - Once the operation completes, the list from 1.) will be populated with customers that match the search criteria.
Updating a Customer
Saves the updates made to a customer. Customers can be updated with new addresses, contact details, or other relevant information.
How it works
- Create a
ProgressListenerand avrp::Service. - Retrieve the customer you want to update (see Get Customer) in a
vrp::Customer. - Change the desired fields of the
vrp::Customer. - Call the
updateCustomer()method from thevrp::Serviceusing thevrp::Customerfrom 2.) andProgressListenerand wait for the operation to be done.
Example
Deleting a Customer
Customers can be deleted individually or in bulk.
If orders are created based on a customer, deleting the customer will also delete the associated orders.
How it works
- Create a
ProgressListenerandvrp::Service. - Call the
deleteCustomer()method from thevrp::Serviceusing the customer object andProgressListenerand wait for the operation to be done.
Example
Retrieving Customer Order History
Get in which optimizations and routes has the customer made order.
How it works
- Create a
ProgressListener, avrp::Serviceand avrp::CustomerOrderList. - Call the
getCustomerOrdersHistory()method from thevrp::Serviceusing thevrp::CustomerOrderListfrom 1.), the ID of the customer and theProgressListener. - Once the operation completes, the
vrp::CustomerOrderListfrom 1.) will be populated.
A vrp::CustomerOrder is an object that contains an order and a map that contains all the optimizations and routes associated with this order.
Error Handling
This API returns specific error codes to indicate potential issues. Below is a summary of common errors and how to resolve them:
| Error Code | Description | Solution |
|---|---|---|
KInvalidInput | Missing required fields or invalid customer data. | Ensure all mandatory fields are properly filled. |
KNotFound | The specified customer ID does not exist. | Verify that the correct customer ID is provided. |
KInternalAbort | Server-side issue or unexpected parsing error. | Retry the request or check API status. |