Use Java to track DPD shipments with DPD Tracking API.
- Real-time DPD tracking.
- Batch DPD tracking.
- Other features to manage your DPD 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 DPD shipments.
Create a tracking (Real-time tracking):
package com.trackingmore.example.dpd;
import com.trackingmore.TrackingMore;
import com.trackingmore.exception.TrackingMoreException;
import com.trackingmore.model.TrackingMoreResponse;
import java.io.IOException;
import java.util.List;
public class CreateDPDTrackingExample {
public static void main(String[] args) {
try {
String apiKey = "your api key";
TrackingMore trackingMore = new TrackingMore(apiKey);
CreateTrackingParams createTrackingParams = new CreateTrackingParams();
createTrackingParams.setTrackingNumber("05222757378047");
createTrackingParams.setCourierCode("dpd");
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.dpd;
import com.trackingmore.TrackingMore;
import com.trackingmore.exception.TrackingMoreException;
import com.trackingmore.model.TrackingMoreResponse;
import java.io.IOException;
import java.util.List;
public class CreateDPDTrackingsExample {
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("01206100616399");
createTrackingParams1.setCourierCode("dpd");
CreateTrackingParams createTrackingParams2 = new CreateTrackingParams();
createTrackingParams2.setTrackingNumber("01305199914553");
createTrackingParams2.setCourierCode("dpd");
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.dpd;
import com.trackingmore.TrackingMore;
import com.trackingmore.exception.TrackingMoreException;
import com.trackingmore.model.TrackingMoreResponse;
import java.io.IOException;
import java.util.List;
public class GetDPDTrackingExample {
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("01206100616399,01305199914553");
trackingParams.setCourierCode("dpd");
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.dpd;
import com.trackingmore.TrackingMore;
import com.trackingmore.exception.TrackingMoreException;
import com.trackingmore.model.TrackingMoreResponse;
import java.io.IOException;
import java.util.List;
public class UpdateDPDTrackingExample {
public static void main(String[] args) {
try {
String apiKey = "your api key";
TrackingMore trackingMore = new TrackingMore(apiKey);
String idString = "9a2f87d7df40d90a5752a8d7d3b98cb5";
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());
}
}
}