PHPBuilder - UPS Shipping Calculator



RSS Twitter
Snippets Shopping Carts

UPS Shipping Calculator

by: Trevor Linton
|
July 15, 2001

Version: 1.0

Type: Function

Category: Shopping Carts

License: BSD License

Description: Simple program that will calculate a UPS shipping rate for any of UPS's shipping types.



function getUPSprice ($shipType,$sendZipcode,$recieveZipcode,$recieveCountry,$weight) {
	$tmp = "AppVersion=1.2&AcceptUPSLicenseAgreement=yes&ResponseType=application/x-ups-rss&ActionCode=3".
		"&RateChart=Regular+Daily+Pickup&DCISInd=0&SNDestinationInd1=0&SNDestinationInd2=0&ResidentialInd=0&PackagingType=00".
		"&ServiceLevelCode=$shipType&ShipperPostalCode=".substr($sendZipcode, 0, 5)."&ConsigneePostalCode=". substr($recieveZipcode, 0, 5).
		"&ConsigneeCountry=$recieveCountry&PackageActualWeight=$weight&DeclaredValueInsurance=0\n\r";
			
	$request = "POST /using/services/rave/qcost_dss.cgi HTTP/1.0\nContent-type: application/x-www-form-urlencoded\nContent-length: " .
		strlen($tmp) . "\n\n" . $tmp;
				
	$this->socket = fsockopen("www.ups.com", 80);
	fputs($this->socket, $request);	
	strtok(fread ($this->socket, 4096), "%");

	for ($i = 0; $i < 12 ;$i++)
		$price = strtok("%");

	fclose($this->socket);
	
	return($price);
}

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Trevor Linton

Comment:



Comment:

(Maximum characters: 1200). You have characters left.