Use Java to track NZ Post shipments with NZ Post Tracking API.
- Real-time NZ Post tracking.
- Batch NZ Post tracking.
- Other features to manage your NZ Post tracking.
Maven
$ <dependency>
$ <groupId>io.github.trackingmores</groupId>
$ <artifactId>trackingmore-sdk-java</artifactId>
$ <version>1.0.3</version>
$ </dependency>
Gradle
$ implementation "io.github.trackingmores:trackingmore-sdk-java:1.0.3"
Get the API key:
To use this API, you need to generate your API key.
- Click here to access TrackingMore admin.
-
Go to the "Developer" section.
-
Click "Generate API Key".
-
Give a name to your API key, and click "Save" .
Then, start to track your NZ Post shipments.
Create a tracking (Real-time tracking):
package com.trackingmore.example.newzealandpost;
import com.trackingmore.TrackingMore;
import com.trackingmore.exception.TrackingMoreException;
import com.trackingmore.model.TrackingMoreResponse;
import java.io.IOException;
import java.util.List;
public class CreateNewZealandPostTrackingExample {
public static void main(String[] args) {
try {
String apiKey = "your api key";
TrackingMore trackingMore = new TrackingMore(apiKey);
CreateTrackingParams createTrackingParams = new CreateTrackingParams();
createTrackingParams.setTrackingNumber("0301006785462006320995");
createTrackingParams.setCourierCode("new-zealand-post");
TrackingMoreResponse<Tracking> result = trackingMore.trackings.CreateTracking(createTrackingParams);
System.out.println(result.getMeta().getCode());
if(result.getData() != null){
Tracking trackings = result.getData();
System.out.println(trackings);
System.out.println(trackings.getTrackingNumber());
}
} catch (TrackingMoreException e) {
System.err.println("error:" + e.getMessage());
} catch (IOException e) {
System.err.println("error:" + e.getMessage());
}
}
}
Create trackings (Max. 40 tracking numbers create in one call):
package com.trackingmore.example.newzealandpost;
import com.trackingmore.TrackingMore;
import com.trackingmore.exception.TrackingMoreException;
import com.trackingmore.model.TrackingMoreResponse;
import java.io.IOException;
import java.util.List;
public class CreateNewZealandPostTrackingsExample {
public static void main(String[] args) {
try {
String apiKey = "your api key";
TrackingMore trackingMore = new TrackingMore(apiKey);
List<CreateTrackingParams> paramsList = new ArrayList<>();
CreateTrackingParams createTrackingParams1 = new CreateTrackingParams();
createTrackingParams1.setTrackingNumber("LK201223662AU");
createTrackingParams1.setCourierCode("new-zealand-post");
CreateTrackingParams createTrackingParams2 = new CreateTrackingParams();
createTrackingParams2.setTrackingNumber("LH290032509AU");
createTrackingParams2.setCourierCode("new-zealand-post");
paramsList.add(createTrackingParams1);
paramsList.add(createTrackingParams2);
TrackingMoreResponse<BatchResults> result = trackingMore.trackings.BatchCreateTrackings(paramsList);
System.out.println(result.getMeta().getCode());
BatchResults batchResults = result.getData();
if(result.getData() != null){
System.out.println(batchResults);
for (BatchItem batchItem : batchResults.getSuccess()) {
String trackingNumber = batchItem.getTrackingNumber();
String courierCode = batchItem.getCourierCode();
System.out.println("Tracking Number: " + trackingNumber);
System.out.println("Courier Code: " + courierCode);
}
for (BatchItem batchItem : batchResults.getError()) {
String trackingNumber = batchItem.getTrackingNumber();
String courierCode = batchItem.getCourierCode();
System.out.println("Tracking Number: " + trackingNumber);
System.out.println("Courier Code: " + courierCode);
}
}
} catch (TrackingMoreException e) {
System.err.println("error:" + e.getMessage());
} catch (IOException e) {
System.err.println("error:" + e.getMessage());
}
}
}
Get status of the shipment:
package com.trackingmore.example.newzealandpost;
import com.trackingmore.TrackingMore;
import com.trackingmore.exception.TrackingMoreException;
import com.trackingmore.model.TrackingMoreResponse;
import java.io.IOException;
import java.util.List;
public class GetNewZealandPostTrackingExample {
public static void main(String[] args) {
try {
String apiKey = "your api key";
TrackingMore trackingMore = new TrackingMore(apiKey);
GetTrackingResultsParams trackingParams = new GetTrackingResultsParams();
# Perform queries based on various conditions
# trackingParams.setTrackingNumbers("LH290032509AU,LK201223662AU");
trackingParams.setCourierCode("new-zealand-post");
trackingParams.setCreatedDateMin("2023-08-23T06:00:00+00:00");
trackingParams.setCreatedDateMax("2023-09-05T07:20:42+00:00");
TrackingMoreResponse<List<Tracking>> result = trackingMore.trackings.GetTrackingResults(trackingParams);
System.out.println(result.getMeta().getCode());
List<Tracking> trackings = result.getData();
for (Tracking tracking : trackings) {
String trackingNumber = tracking.getTrackingNumber();
String courierCode = tracking.getCourierCode();
System.out.println("Tracking Number: " + trackingNumber);
System.out.println("Courier Code: " + courierCode);
}
} catch (TrackingMoreException e) {
System.err.println("error:" + e.getMessage());
} catch (IOException e) {
System.err.println("error:" + e.getMessage());
}
}
}
Update a tracking by ID:
package com.trackingmore.example.newzealandpost;
import com.trackingmore.TrackingMore;
import com.trackingmore.exception.TrackingMoreException;
import com.trackingmore.model.TrackingMoreResponse;
import java.io.IOException;
import java.util.List;
public class UpdateNewZealandPostTrackingExample {
public static void main(String[] args) {
try {
String apiKey = "your api key";
TrackingMore trackingMore = new TrackingMore(apiKey);
String idString = "9a1339cb81ec08b52985867d176a0ba4";
UpdateTrackingParams updateTrackingParams = new UpdateTrackingParams();
updateTrackingParams.setCustomerName("New name");
updateTrackingParams.setNote("New tests order note");
TrackingMoreResponse<UpdateTracking> result = trackingMore.trackings.UpdateTrackingByID(idString, updateTrackingParams);
System.out.println(result.getMeta().getCode());
System.out.println(result.getData());
if(result.getData() != null){
UpdateTracking updateTracking= result.getData();
System.out.println(updateTracking);
System.out.println(updateTracking.getTrackingNumber());
}
} catch (TrackingMoreException e) {
System.err.println("error:" + e.getMessage());
} catch (IOException e) {
System.err.println("error:" + e.getMessage());
}
}
}