Logistics Automation - Routing Task Assignment
Tags: powerfuldevs, logistics, automation, powerplatforms
Published: 2023-03-07 06:07:48

**Routing Task Assignment**:
A workflow app for parcel logistics that allows users to self-check-in parcel tasks and also provides routing recommendations could have several benefits for both the logistics provider and the end customer

**Conceptual Architecture View**:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vo5q770qjrfdm7putbme.png)

**Platform Setup**:
Added 2 more columns to the share point list. One a choice which would capture the Status of the Order and another column to capture the user Email ID to select the assigned task 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9taeuek493a1k0jytoa0.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhieoi79rkqol7v298lw.png)

**_Bing as a Data Connector_**:
Its a premium connector 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qf8qy3ey80jlla91ky04.png)

**_Enabling Map Controls / Geospatial_**: 
https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/geospatial-overview

**_Enabling Barcode Control_**: 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lghjhb6uhisjwxfm1hbq.png)


**Setup the Scanner**:
**Scanner barcode Control**:
This out of the box control enables you to read barcode which was created in the previous step. To access the barcode data leverage the below code 

```
BarcodeScanner1.Value
```

![Image description]
(https://media.giphy.com/media/KEzHnP3XJwlgwahGFU/giphy.gif)

**Routing Recommendation**:

1.First it to get the Origin and destination postcode for the sharepoint list site based on the barcode scanned. 

```
LookUp(GeoMap,'Consignment ID'=BarcodeScanner1.Value).FromAdd
```

2.Once I save both the origin and destination postcode for the  Routing recommendation task the next step is to get the Longitude and the Latitude for the post code. 

```
BingMaps.GetLocationByAddress({postalCode:OrginPost_1.Text}).point.coordinates.latitude
BingMaps.GetLocationByAddress({postalCode:OrginPost_1.Text}).point.coordinates.longitude
```

3.Create a table as a variable on the screen to pass the value to the Map control 

```
Set(SCMapTemp,Table({Latitude:BingMaps.GetLocationByAddress({postalCode:OrginPost_1.Text}).point.coordinates.latitude,
Longitude:BingMaps.GetLocationByAddress({postalCode:OrginPost_1.Text}).point.coordinates.longitude},
{Latitude:BingMaps.GetLocationByAddress({postalCode:DestPost_1.Text}).point.coordinates.latitude,
Longitude:BingMaps.GetLocationByAddress({postalCode:DestPost_1.Text}).point.coordinates.longitude}))
```

4.The above step (getting the co-ordinates) could be ignored if you already have the longitude and latitude data which would mean you need not configure the BingMaps data connector. Now insert the Map controls and pass the above table as data point to get the routing recommendation 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1llwcn3a387mss8i994.png)

**_Enable Routing on the Map control_**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwalmq4j8caohf2dnlsb.png)

1.Add the data source
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ortpdcsge3vlt9ih648m.png)

2.Get the distance from the Map control (data always in meters)

```
Concatenate((Map2_1.RouteDirection.LengthInMeters)/1000," KM")
```

3.Get the time from the Map control (data always in seconds)

```
With(
    {
        varTravelTime: Time(
            0,
            0,
            Map2_1.RouteDirection.TravelTimeInSeconds
        )
    },
    With(
        {
            varHours: Hour(varTravelTime),
            varMinutes: Mod(
                Minute(varTravelTime),
                60
            )
        },
        Coalesce(
            Concatenate(
                If(
                    varHours <> 0,
                    Text(
                        varHours,
                        "0"
                    ) & " hr "
                ),
                If(
                    varMinutes <> 0,
                    Text(
                        varMinutes,
                        "0"
                    ) & " min"
                )
            ),
            "0 hr"
        )
    )
)
```

The Routing recommendation would looks something as below

![Image description]
(https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExMWVhZDk0NmY4Y2M0NTUzODFjZDE0ZGMxNDNiNGY2ZmRiMmUwYWIxOSZjdD1n/Zf5OuGM49eEkUgXY7H/giphy.gif)


**Task Checkout**:
Adding a self checkin button to perform the below 2 tasks. Have leveraged the Office connector to get the user id

1. Update the sharepoint list Order status and enable the user to assign the task 

```
Patch(GeoMap,LookUp(GeoMap,'Consignment ID'= BarcodeScanner1.Value),{Status:{ Value: "03"}});
Patch(GeoMap,LookUp(GeoMap,'Consignment ID'= BarcodeScanner1.Value),{AssignedTo:User().Email})
```
2. Send an email to notify the user 

```
Office365Outlook.SendEmailV2(User().Email,"ConsignmentID  :" &BarcodeScanner1.Value,
"Dear :" &User().FullName& ","&
"The Self Check-In is now completed. Proceed to deliver the order" &
"<br>" &
"<h3>Job Information Details </h3>" &
"The Consignment ID Reference   :" &BarcodeScanner1.Value &
"<br>" &
"The Pick Up Location Postcode  :" &OrginPost_1.Text &
"<br>" &
"The Drop off Location Postcode :" &DestPost_1.Text &
"<br>" &
"Estimated Time for Travel      :" &EstTimeV_2.Text &
"<br>" &
"Estimated Travel Distance      :" &EstDistV_1.Text
);
```
Task self checkout would look something as below

![Image description]
(https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZWM3ZGYzNmI3ZDhiOTZhYzg3NWI5ODBjZDJiMzEwYjdhNWZlZmVhZSZjdD1n/fkTLOH7TyAMDgKS9ei/giphy.gif)

**Task Automation Benefit**:

_Improved efficiency_: With a self-check-in feature, the logistics provider can save time by eliminating the need for manual check-in and processing. This can help to speed up the overall parcel delivery process and increase efficiency.

_Reduced errors_: By allowing customers to check in their own parcels, the likelihood of errors or mistakes in the check-in process can be reduced. This can help to improve accuracy and ensure that parcels are properly accounted for.

_Enhanced customer experience_: A self-check-in feature can provide customers with greater convenience and flexibility, as they can check in their parcels at their own convenience. Additionally, routing recommendations can help customers to choose the most efficient and cost-effective delivery options, which can help to improve overall satisfaction.

**<u>Product Documentation</u>**:

- **Barcode Scanner Control**:https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/controls/control-new-barcode-scanner

- **Bing Maps Connector**: https://learn.microsoft.com/en-us/connectors/bingmaps/

- **Maps Control**:https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/geospatial-component-map