Australia Post shipping rate calculation
Is anyone having any experience with any eCommerce application where you have calculated shipping rate on fly. I am in particular referring to Australia Post service.
Could you please guide me in right direction. I am thinking of using Provider pattern by which I can plugin any shipping provider according to user's profile.
Explanation as per Australia Post is what I am looking for but if anyone has got any suggestions using any other provider, I am fine.
FYI - I am referring to ASP.net, c# (.Net 4.0开发者_开发知识库) Thanks in advance,
Australia Post has a Delivery Rate Calculator API.
The following instructions have been developed to enable you to access the functionality of the Post eDeliver Delivery Rate Calculator (DRC) directly from your merchant Website. The DRC is available to merchants who would like to offer online estimation of delivery charges to their customers.
I haven't used it so can't tell you anymore about it.
Step-1: create account and get Key
http://auspost.com.au/
Step2 : create function in your MyPage.aspx.cs page
protected string CalculateCharge(string lngth, string wdth, string hgth, string fpcode, string tpcode, string weght, string service_code)
{
string url = "https://auspost.com.au/api/postage/parcel/domestic/calculate.xml?";
url = url + "length=" + HttpUtility.UrlEncode(lngth) + "&width=" + HttpUtility.UrlEncode(wdth) + "&height=" + HttpUtility.UrlEncode(hgth) + "&from_postcode=" + HttpUtility.UrlEncode(fpcode) + "&to_postcode=" + HttpUtility.UrlEncode(tpcode) + "&option_code=&weight=" + HttpUtility.UrlEncode(weght) + "&service_code=" + HttpUtility.UrlEncode(service_code) + "&extra_cover=";
Uri objURI = new Uri(url);
HttpWebRequest objwebreq = (HttpWebRequest)WebRequest.Create(objURI);
objwebreq.ContentType = "text/xml;charset=utf-8;";
objwebreq.Method = "Get";
objwebreq.Timeout = 15000;
objwebreq.Headers.Set("AUTH-KEY", "here enter your key");
HttpWebResponse objWebResponse = (HttpWebResponse)objwebreq.GetResponse();
Stream objStream = objWebResponse.GetResponseStream();
StreamReader objStreamReader = new StreamReader(objStream);
return objStreamReader.ReadToEnd();
}
Step-3: Pass Parameter in function button click:
protected void btnShippingCalculate_Click(object sender, EventArgs e)
{
string xmlresult = CalculateCharge("10", "10", "10", "3216","3217" ,"5", "AUS_PARCEL_REGULAR");
DataSet ds = new DataSet();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xmlresult);
ds.ReadXml(new System.IO.StringReader(doc.OuterXml));
GridView1.DataSource = ds;
GridView1.DataBind();
}
Note:
service_code:
AUS_PARCEL_REGULAR
AUS_PARCEL_EXPRESS
AUS_PARCEL_PLATINUM
Weight: in KG
That's It!!!
精彩评论