Filtering objects inside filter expression configuration fields or vehicle_label field
Within the SWAT API model, some objects support flexible user-defined filtering via "filter expression" within processing pipelines. Examples include processors and vehicle labels. These filtering expressions enable selective object inclusion in processing, employing syntax similar to QuerySet filters. For instance, to include soft-deleted bookings in processing, a booking filter expression can be applied during the process.
{
"and": [
{
"pk__in": [
<some_booking_id_list>
]
},
{
"is_invalidated__exact": true
}
]
}
Most object fields can be used to apply this filtering approach.
Using filters in vehicle_labels field
The same approach can be applied to manage the matching process of labels between vehicles, bookings and nodes.
The booking.vehicle_labels field in the booking object lists vehicle labels of vehicles eligible for delivering the order. In the following example, optimizing orders with this vehicle_labels field ensures that only vehicles with T01, T02, or T03 labels are used to fulfill these orders:
"vehicle_labels": {
"or": [
"T01",
"T02",
"T03"
]
}
This feature proves beneficial when flexible grouping is needed with established rules for fleets and orders.
or another example,
{"and":
[{"or": ["2", "3"]}, {"not": {"and": ["4", "5"]}}]
}
Leveraging relations
Filtering expressions support relations between the objects that can be ser using __ syntax, for example, the following booking_filter_expression allows to select bookings that are in prepared state, as well as those that have operations_locations set, which in turn belongs to locations_groups that contain code N10. This is an effective way of doing nested lookups which support both one to many, and may to many relations.
{
"state__in": [
"prepared"
],
"pickup_operations_location__group__code__in": [
"N10"
]
}