Vehicles
The Vehicle class enables users to manage their fleet efficiently within the Fleet Management SDK. Vehicles play a crucial role in optimizing logistics and route planning. This API provides endpoints to:
- Add new vehicles to the fleet.
- Retrieve and update vehicle details such as type, capacity, and status.
- Delete vehicles when they are no longer in use.
- Monitor last known positions and fuel consumption to enhance operational efficiency.
Vehicle Structure
Each vehicle object consists of the following attributes:
| Name | Type | Description | Setter | Getter |
|---|---|---|---|---|
| Id | LargeInteger | Unique identifier for the vehicle. | ❌ | ✅ |
| Type | EVehicleType | The type of the vehicle. | ✅ | ✅ |
| Status | EVehicleStatus | The status of the vehicle. | ✅ | ✅ |
| Name | String | The name of the vehicle. | ✅ | ✅ |
| Manufacturer | String | The manufacturer of the vehicle. | ✅ | ✅ |
| Model | String | The model of the vehicle. | ✅ | ✅ |
| LicensePlate | IString | The license plate of the vehicle. | ✅ | ✅ |
| FuelType | EFuelType | The fuel type of the vehicle. | ✅ | ✅ |
| LastPosition | Coordinates | The last known position of the vehicle. | ✅ | ✅ |
| Consumption | float | The consumption of the vehicle (l/100 km or kWh/100 km). | ✅ | ✅ |
| BikePower | float | The power of the bicycle in watts. | ✅ | ✅ |
| BikerWeight | float | The minimum weight that the vehicle can carry (only for bikes). | ✅ | ✅ |
| MaxLoadWeight | float | The maximum weight that the vehicle can carry. | ✅ | ✅ |
| MaxLoadCube | float | The maximum cubic volume that the vehicle can carry. | ✅ | ✅ |
| Height | float | The height of the vehicle. | ✅ | ✅ |
| Width | float | The width of the vehicle. | ✅ | ✅ |
| Weight | float | The weight of the vehicle. | ✅ | ✅ |
| Length | float | The length of the vehicle. | ✅ | ✅ |
| AxleLoad | float | The axle load of the vehicle. | ✅ | ✅ |
| FixedCost | float | The fixed cost of the vehicle. | ✅ | ✅ |
| CostPerHour | float | The cost per hour of the vehicle. | ✅ | ✅ |
| StartTime | int | The start time of the working program, in minutes from midnight. | ✅ | ✅ |
| EndTime | int | The end time of the working program, in minutes from startTime. | ✅ | ✅ |
Managing Vehicles
Creating a Vehicle
Async adds a vehicle in the list of vehicles of the API user. The list of vehicles represents the fleet of the user.
If the operation is successful, the vehicle will have an id assigned; which can be retrieved using the method vehicle.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::Vehicleand set the desired fields. - Create a
ProgressListenerandvrp::Service. - Call the
addVehicle()method from thevrp::Serviceusing thevrp::VehicleandProgressListenerand wait for the operation to be done.
Example
Retrieving Vehicles
There are two ways to retrieve vehicle data:
a) 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.
b) Get All Vehicles (with optional filtering)
Returns all vehicles of the API user (which contain the search term).
How it works
- Create a
ProgressListener, avrp::Serviceand avrp::VehicleList. - Call the
getAllVehicles()method from thevrp::Serviceusing the list from 1.) and theProgressListener. - Once the operation completes, the list from 1.) will be populated.
Updating a Vehicle
Vehicles can be updated with new status, consumption rate, or other relevant information.
If the consumption was changed and the vehicle was used in a route, the next time you access (retrieve) the route, its cost will be updated considering the new consumption of the vehicle.
How it works
- Create a
ProgressListenerand avrp::Service. - Retrieve the vehicle you want to update (see [Get Vehicle]./Vehicle#a-get-a-vehicle-by-id)) in a
vrp::Vehicle. - Change the desired fields of the
vrp::Vehicle. - Call the
updateVehicle()method from thevrp::Serviceusing thevrp::Vehiclefrom 2.) and theProgressListenerand wait for the operation to be done.
Example
Deleting a Vehicle
Vehicles can be deleted individually or in bulk.
Deleted vehicle will no longer appear in the routes to which the vehicle was assigned; their cost will be re-calculated using the default values (the vehicle's type is a car which runs on standard gasoline and has a consumption of 7.5 l/100km).
How it works
- Create a
ProgressListenerandvrp::Service. - Call the
deleteVehicle()method from thevrp::Serviceusing the vehicle's id andProgressListenerand wait for the operation to be done.
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 vehicle data. | Ensure all mandatory fields are properly filled. |
KNotFound | The specified vehicle ID does not exist. | Verify that the correct vehicle ID is provided. |
KInternalAbort | Server-side issue or unexpected parsing error. | Retry the request or check API status. |