cancel
Showing results for 
Search instead for 
Did you mean: 
gabe
First-timer (legacy)
Status: Started
i would like shipstation to be able to choose the cheapest shipping method for each order that comes in. currently, i use UPS & USPS and i have to manually select between the 2 services to see which one is cheaper. this process is very time consuming and needs to be done on an order by order basis. i would like shipstation to automatically upload the cheapest shipping method so i can print all the labels at once.
112 Comments
gabe
First-timer (legacy)
please add a feature that automatically chooses the cheapest service for each order. its very time consuming for me to select the cheapest service for each order.
email
First-timer (legacy)
Yes, please make this happen. Shippers don't want to spend time researching each order. At least let us make our preferred carrier the default on the calculator! Thanks.
laura1
First-timer (legacy)
I use a "Retail Standard" as a mapped option from our ERP. I would like to see it as: If Retail standard, pick least expensive between UPS ground & Fedex Ground. Thanks for working on this!
joseph1
First-timer (legacy)
What is the delay in this SHIPSTATION? you guys already have a calculator doing this job if we do it manually one by one integrate it in bulk already we pay thousands of dollars per month especially when you are SFP when this should be the 1st feature that you guys have we need to spend endless hours a day searching for the cheapest options when its your job and service we pay for is for you to save us money and time and your failing with this!!!!
brian2
First-timer (legacy)
This is a deal breaker that this does not exist. The exact functionality exists in Ship Works. Why not in Ship Station??? We are considering moving over to Ship Station, but with processing thousands of orders a day, there is no way we can do this manually.
Status changed to: Started
SuperMgr-Sarah
Community Manager
Community Manager

This feature is currently in development!

douglsmith
Occasional Contributor

Rather than just choosing the cheapest service, I would prefer to see the options with the least expensive pre-selected. That would also give the ability to choose differently if there is only a small price increase for a quicker or more reliable service.

Status changed to: Started
SuperMgr-Sarah
Community Manager
Community Manager
 
SuperMgr-Sarah
Community Manager
Community Manager

@douglsmith

 

The first iteration of this tool is going to focus on auto-selecting the cheapest service from a group of services you can configure yourself (as this is one of the most requested features we have). For example, if you want the cheapest standard service, cheapest 2-day service, or cheapest overnight service you can create a group that contains all available services for your connected carriers that you might want to use in that specific service class - you would then choose the group for which you want the cheapest service and ShipStation will automatically assign the service with the cheapest rate. 

 

You'll be able to configure your service "groups" in any way that best suits your needs. Future iterations will expand the feature to other criteria... for example, you might want ShipStation to select the fastest service rather than the cheapest. 

 

If I'm understanding your request correctly, you would want some type of message to pop up so you could compare the rates side-by-side yourself and choose, for example, a 2-day service instead of standard if it was only slightly more expensive, rather than having ShipStation auto-assign, yes? A future state of the feature that has been discussed (but would be somewhat far off) would allow you to set some sophisticated rules that say something like "if service A is less than $x or x% more than service B, choose service A"

 

We'd love to get some thoughts from the community on this!

janitorialplumb
New Contributor

I wrote a script that does this. Feel free to use it. 

 

I set it to run through every order that is awaiting shipment and tagged white.

Some notes;

I made it only rate UPS, Fedex, and USPS. UPS and Fedex will only rate using your main account.

It will not rate USPS Media Mail and any flat rate boxes.

Please let me know of any questions or concerns.

 

You can run it off my site: http://bulkbuys.net/ssrates/getratesss.php?apikey=yourapikey&apisecret=yourapisecret

 

of you can can  upload the script onto your own site and run it there. Just call it using your apikey and apisecret.

 

This is the script;

<?php

$apikey = $_GET['apikey'];
$apisecret = $_GET['apisecret'];

$theapikey = ' Basic ' . base64_encode($apikey . ':' . $apisecret);

 

for ($i = 1; $i <= 2; $i++) {
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/orders/listbytag?orderStatus=awaiting_shipment&tagId=85175&page=". $i ."&pageSize=200",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Host: ssapi.shipstation.com",
"Authorization:" . $theapikey,
"Accept: application/json"
),
));

$strorders = curl_exec($curl);
curl_close($curl);

$orders = json_decode($strorders,true);


foreach($orders['orders'] as $order){

$orderid = $order['orderId'];
$orderNumber = $order['orderNumber'];
$warehouseid =$order['advancedOptions']['warehouseId'];
$tozipcode = $order['shipTo']['postalCode'];
$weightvalue = $order['weight']['value'];
$weightunits = $order['weight']['units'];
$toCountry = $order['shipTo']['country'];
$s_residential = $order['shipTo']['residential'];
$carrierCode = $order['carrierCode'];
$serviceCode = $order['serviceCode'];
$packageCode = $order['packageCode'];
$confirmation = $order['confirmation'];
$dimensions = $order['dimensions'];






if($s_residential){$residential = "true";}else{$residential = "false";}


$cheapestservice = calcrates($theapikey,$orderNumber,$warehouseid,$tozipcode,$toCountry,$weightvalue,$weightunits,$residential,$packageCode,$confirmation);

echo "Cheapest service is : " ,$orderNumber," ",$cheapestservice[0]," " ,$cheapestservice[1]," ",$cheapestservice[2]," ",$cheapestservice[3];

setcheapestrates($theapikey,$orderNumber,$cheapestservice[0] ,$cheapestservice[2],$cheapestservice[3],$order['orderDate'],$order['billTo'],$order['shipTo']);
}

}
function setcheapestrates($theapikey,$orderNumber,$cheapestservice,$cheapestpackage,$cheapestcarrier,$orderDate,$billTo,$shipTo){
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/orders/createorder",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\n \"orderNumber\": \"".$orderNumber."\",\n \"orderKey\": \"".$orderNumber."\",\n \"orderDate\": \"".$orderDate."\",\n \"orderStatus\": \"awaiting_shipment\",\n \"billTo\": ".json_encode($billTo).",\n \"shipTo\": ".json_encode($shipTo). ",\n \"carrierCode\": \"".$cheapestcarrier."\",\n \"serviceCode\": \"".$cheapestservice."\",\n \"packageCode\": \"".$cheapestpackage."\"\n}",
CURLOPT_HTTPHEADER => array(
"Host: ssapi.shipstation.com",
"Authorization:" . $theapikey,
"Content-Type: application/json"
),
));

$response = curl_exec($curl);

curl_close($curl);
echo "completed /n";
}
function calcrates($theapikey,$orderid,$warehouseid,$tozipcode,$toCountry,$weightvalue,$weightunits,$residential,$packagecode,$confirmation){
$frompostalcode = GetWarehouseLocation($warehouseid,$theapikey);

//now lets set up seperate calcs for fedex,ups, usps
$carriers = array("stamps_com","ups","fedex");


foreach ($carriers as $carrier){
$theheader = "{\n \"carrierCode\": \"".$carrier."\",\n \"serviceCode\": null,\n \"packageCode\": null,\n \"fromPostalCode\": \""
.$frompostalcode."\",\n \"toCountry\": \""
.$toCountry."\",\n \"toPostalCode\": \""
.$tozipcode."\",\n \"weight\": {\n \"value\": "
.$weightvalue.",\n \"units\": \""
.$weightunits."\"\n },\n \"dimensions\": {\n \"units\": \"inches\",\n \"length\": 7,\n \"width\": 5,\n \"height\": 6\n },\n \"confirmation\": \"".$confirmation.
"\",\n \"residential\": ".$residential . "\n }"; //\"advancedOptions\": \"{ \n \"billToMyOtherAccount\":117945\n} \n

//this works

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/shipments/getrates",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>$theheader,
CURLOPT_HTTPHEADER => array(
"Host: ssapi.shipstation.com",
"Authorization:" . $theapikey,
"Content-Type: application/json"
),
));

$response = curl_exec($curl);

curl_close($curl);

$resjson = json_decode($response,true);

//now lets parse teh rates, only evaluating rates with the term package or fedex or ups in the name
foreach ($resjson as $prate){
$serviceName = $prate['serviceName'];

if ((str_contains($serviceName,'USPS') AND str_contains($serviceName,'Package') AND (!str_contains($serviceName,'Media') AND (!str_contains($serviceName,'Select'))))
OR str_contains($serviceName,'UPS')
OR (str_contains($serviceName,'FedEx') AND (!str_contains($serviceName,'select')))){
$shipmentCost = $prate['shipmentCost'];
$otherCost = $prate['otherCost'];
$serviceCode = $prate['serviceCode'];
// $SellerProviderId = $prate['SellerProviderId'];

$fullrategp[$serviceCode] = $shipmentCost + $otherCost;
}

}
}

//now we run this again using current pacakgecode
foreach ($carriers as $carrier){
$theheader = "{\n \"carrierCode\": \"".$carrier."\",\n \"serviceCode\": null,\n \"packageCode\": \"".$packagecode."\",\n \"fromPostalCode\": \""
.$frompostalcode."\",\n \"toCountry\": \""
.$toCountry."\",\n \"toPostalCode\": \""
.$tozipcode."\",\n \"weight\": {\n \"value\": "
.$weightvalue.",\n \"units\": \""
.$weightunits."\"\n },\n \"dimensions\": {\n \"units\": \"inches\",\n \"length\": 7,\n \"width\": 5,\n \"height\": 6\n },\n \"confirmation\": \"".$confirmation."\",\n \"residential\": ".$residential."\n}";

//this works

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/shipments/getrates",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>$theheader,
CURLOPT_HTTPHEADER => array(
"Host: ssapi.shipstation.com",
"Authorization:" . $theapikey,
"Content-Type: application/json"
),
));

$response = curl_exec($curl);

curl_close($curl);

$resjson = json_decode($response,true);

//now lets parse teh rates, only evaluating rates with the term package or fedex or ups in the name
foreach ($resjson as $prate){
$serviceName = $prate['serviceName'];

if ((str_contains($serviceName,'USPS') AND str_contains($serviceName,'Package') AND (!str_contains($serviceName,'Media') AND (!str_contains($serviceName,'Select'))))
OR str_contains($serviceName,'UPS')
OR (str_contains($serviceName,'FedEx') AND (!str_contains($serviceName,'select')))){
$shipmentCost = $prate['shipmentCost'];
$otherCost = $prate['otherCost'];
$serviceCode = $prate['serviceCode'];

$fullratecp[$serviceCode] = $shipmentCost + $otherCost;
}

}
}

//now compare geeneric package to custom pacakge
$cheapestgp = min($fullrategp);
$cheapestcp = min($fullratecp);

if ($cheapestgp < $cheapestcp){
$cheapestservice = array_keys($fullrategp, min($fullrategp));
$cheapestprice = $cheapestgp;
$cheapestpackage = "";
}else{
$cheapestservice = array_keys($fullratecp, min($fullratecp));
$cheapestprice = $cheapestcp;
$cheapestpackage = $packagecode;
}

//carrier
$cheapestcarrier ="";
if (str_contains($cheapestservice[0],'USPS')){$cheapestcarrier = 'USPS';} elseif (str_contains($cheapestservice[0],'UPS')){$cheapestcarrier = 'UPS';} elseif (str_contains($cheapestservice[0],'Fedex')){$cheapestcarrier = 'Fedex';}
return [$cheapestservice[0],$cheapestprice,$cheapestpackage,$cheapestcarrier];
}

 

function GetWarehouseLocation($warehouseid,$theapikey){
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/warehouses/" . $warehouseid ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Host: ssapi.shipstation.com",
"Authorization:" . $theapikey,
"Accept: application/json"
),
));

$response = curl_exec($curl);
curl_close($curl);


$resjson = json_decode($response,true);
$whpostalcode = $resjson['originAddress']['postalCode'];

return $whpostalcode;
}

?>