Freight

Ejemplo 6 – Integración con la Toll for Maps API

El servicio Freight API puede integrarse con la API Toll for Maps, de modo que además de la devolución de las tarifas de peaje, también se proporcionará el cálculo del flete.

El proceso consiste simplemente en añadir los parámetros de la Freight API al cuerpo de la solicitud a las Toll for Maps APIs.

No necesitará incluir el parámetro distance, ya que la distancia recorrida estará en la respuesta de la Directions API.

El siguiente ejemplo muestra una solicitud de ruta entre São Paulo – SP y Campinas – SP, a ser recorrida por un camión de 4 ejes dobles, incluyendo cálculos de peaje y flete (Carga: Granel sólido / Tipo de operación: D).

Endpoint utilizado:https://api.maplink.global/toll/v1/directions?vehicleType={TIPO_VEICULO} (Method: POST)

El body de la solicitud debe contener la respuesta de la Directions API, además de los parámetros de la Freight API, como se muestra en el siguiente ejemplo:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
{
//Resposta da Directions API
"maplink": {
"freight": {
"operationType": [
"D"
],
"goodsType": [
"GRANEL_SOLIDO"
],
"axis": [
"4"
],
"roundTrip": false,
"backEmpty": false,
"otherCosts": [
{
"name": "ICMS",
"type": "PERCENT",
"value": "5"
},
{
"name": "Lucro",
"type": "PERCENT",
"value": "20"
},
{
"name": "TaxaFixa",
"type": "FIXED",
"value": "500"
}
],
"date": "2021-10-02"
}
}
}
{ //Resposta da Directions API "maplink": { "freight": { "operationType": [ "D" ], "goodsType": [ "GRANEL_SOLIDO" ], "axis": [ "4" ], "roundTrip": false, "backEmpty": false, "otherCosts": [ { "name": "ICMS", "type": "PERCENT", "value": "5" }, { "name": "Lucro", "type": "PERCENT", "value": "20" }, { "name": "TaxaFixa", "type": "FIXED", "value": "500" } ], "date": "2021-10-02" } } }
{
    //Resposta da Directions API 
    "maplink": {
        "freight": {
            "operationType": [
                "D"
            ],
            "goodsType": [
                "GRANEL_SOLIDO"
            ],
            "axis": [
                "4"
            ],
            "roundTrip": false,
            "backEmpty": false,
            "otherCosts": [
                {
                    "name": "ICMS",
                    "type": "PERCENT",
                    "value": "5"
                },
                {
                    "name": "Lucro",
                    "type": "PERCENT",
                    "value": "20"
                },
                {
                    "name": "TaxaFixa",
                    "type": "FIXED",
                    "value": "500"
                }
            ],
            "date": "2021-10-02"
        }
    }
}

A continuación encontrará la respuesta completa:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
{
"results": [
{
"legs": [
{
"tolls": [
{
"id": "13",
"name": "Pedágio - Campo Limpo",
"address": "SP 348 - Rod. dos Bandeirantes",
"city": "Campo Limpo",
"state": {
"name": "São Paulo",
"code": "SP"
},
"country": "Brasil",
"concession": "Autoban",
"direction": "NORTH",
"coordinates": {
"latitude": -23.3260346,
"longitude": -46.8231453
},
"serviceTypes": [
{
"serviceId": "48",
"name": "Via Facil"
},
{
"serviceId": "35353480390470101",
"name": "ANTTCODE"
}
],
"price": 31.80
},
{
"id": "73",
"name": "Pedágio - Valinhos Norte",
"address": "SP 330 - Rod. Anhanguera Km 82",
"city": "Valinhos",
"state": {
"name": "São Paulo",
"code": "SP"
},
"country": "Brasil",
"concession": "Autoban",
"direction": "NORTHWEST",
"coordinates": {
"latitude": -23.01295484,
"longitude": -47.0230555
},
"serviceTypes": [
{
"serviceId": "50",
"name": "Via Facil"
},
{
"serviceId": "35353300820000101",
"name": "ANTTCODE"
}
],
"price": 31.50
}
],
"legTotalCost": 63.30
}
],
"freight": {
"source": "RESOLUÇÃO No 5.949, DE 13 DE JULHO DE 2021",
"results": {
"D": {
"4": {
"GRANEL_SOLIDO": {
"value": 369.97,
"otherCosts": {
"ICMS": 18.50,
"Lucro": 74.00,
"TaxaFixa": 500
}
}
}
}
},
"minimumFreight": 369.97,
"minimumFreightWithCosts": 962.47
},
"totalCost": 63.30,
"routeFreightCost": 1025.77
}
]
}
{ "results": [ { "legs": [ { "tolls": [ { "id": "13", "name": "Pedágio - Campo Limpo", "address": "SP 348 - Rod. dos Bandeirantes", "city": "Campo Limpo", "state": { "name": "São Paulo", "code": "SP" }, "country": "Brasil", "concession": "Autoban", "direction": "NORTH", "coordinates": { "latitude": -23.3260346, "longitude": -46.8231453 }, "serviceTypes": [ { "serviceId": "48", "name": "Via Facil" }, { "serviceId": "35353480390470101", "name": "ANTTCODE" } ], "price": 31.80 }, { "id": "73", "name": "Pedágio - Valinhos Norte", "address": "SP 330 - Rod. Anhanguera Km 82", "city": "Valinhos", "state": { "name": "São Paulo", "code": "SP" }, "country": "Brasil", "concession": "Autoban", "direction": "NORTHWEST", "coordinates": { "latitude": -23.01295484, "longitude": -47.0230555 }, "serviceTypes": [ { "serviceId": "50", "name": "Via Facil" }, { "serviceId": "35353300820000101", "name": "ANTTCODE" } ], "price": 31.50 } ], "legTotalCost": 63.30 } ], "freight": { "source": "RESOLUÇÃO No 5.949, DE 13 DE JULHO DE 2021", "results": { "D": { "4": { "GRANEL_SOLIDO": { "value": 369.97, "otherCosts": { "ICMS": 18.50, "Lucro": 74.00, "TaxaFixa": 500 } } } } }, "minimumFreight": 369.97, "minimumFreightWithCosts": 962.47 }, "totalCost": 63.30, "routeFreightCost": 1025.77 } ] }
{
    "results": [
        {
            "legs": [
                {
                    "tolls": [
                        {
                            "id": "13",
                            "name": "Pedágio - Campo Limpo",
                            "address": "SP 348 - Rod. dos Bandeirantes",
                            "city": "Campo Limpo",
                            "state": {
                                "name": "São Paulo",
                                "code": "SP"
                            },
                            "country": "Brasil",
                            "concession": "Autoban",
                            "direction": "NORTH",
                            "coordinates": {
                                "latitude": -23.3260346,
                                "longitude": -46.8231453
                            },
                            "serviceTypes": [
                                {
                                    "serviceId": "48",
                                    "name": "Via Facil"
                                },
                                {
                                    "serviceId": "35353480390470101",
                                    "name": "ANTTCODE"
                                }
                            ],
                            "price": 31.80
                        },
                        {
                            "id": "73",
                            "name": "Pedágio - Valinhos Norte",
                            "address": "SP 330 - Rod. Anhanguera Km 82",
                            "city": "Valinhos",
                            "state": {
                                "name": "São Paulo",
                                "code": "SP"
                            },
                            "country": "Brasil",
                            "concession": "Autoban",
                            "direction": "NORTHWEST",
                            "coordinates": {
                                "latitude": -23.01295484,
                                "longitude": -47.0230555
                            },
                            "serviceTypes": [
                                {
                                    "serviceId": "50",
                                    "name": "Via Facil"
                                },
                                {
                                    "serviceId": "35353300820000101",
                                    "name": "ANTTCODE"
                                }
                            ],
                            "price": 31.50
                        }
                    ],
                    "legTotalCost": 63.30
                }
            ],
            "freight": {
                "source": "RESOLUÇÃO No 5.949, DE 13 DE JULHO DE 2021",
                "results": {
                    "D": {
                        "4": {
                            "GRANEL_SOLIDO": {
                                "value": 369.97,
                                "otherCosts": {
                                    "ICMS": 18.50,
                                    "Lucro": 74.00,
                                    "TaxaFixa": 500
                                }
                            }
                        }
                    }
                },
                "minimumFreight": 369.97,
                "minimumFreightWithCosts": 962.47
            },
            "totalCost": 63.30,
            "routeFreightCost": 1025.77
        }
    ]
}