static final String AD_UNIT_ID = "INSERT_AD_UNIT_ID_HERE";
public static void runExample(DfpServices dfpServices, DfpSession session, String adUnitId)
throws Exception {
// Get the InventoryService.
InventoryServiceInterface inventoryService =
dfpServices.get(session, InventoryServiceInterface.class);
// Get the ad unit.
AdUnit adUnit = inventoryService.getAdUnit(adUnitId);
// Add the size 468x60 to the ad unit.
List<AdUnitSize> adUnitSizes = Lists.<AdUnitSize>newArrayList(adUnit.getAdUnitSizes());
Size size = new Size();
size.setWidth(468);
size.setHeight(60);
AdUnitSize adUnitSize = new AdUnitSize();
adUnitSize.setSize(size);
adUnitSize.setEnvironmentType(EnvironmentType.BROWSER);
adUnitSizes.add(adUnitSize);
adUnit.setAdUnitSizes(adUnitSizes.toArray(new AdUnitSize[] {}));
// Update the ad units on the server.
AdUnit[] adUnits = inventoryService.updateAdUnits(new AdUnit[] {adUnit});
for (AdUnit updatedAdUnit : adUnits) {
List<String> adUnitSizeStrings = Lists.newArrayList();
for (AdUnitSize updatedAdUnitSize : updatedAdUnit.getAdUnitSizes()) {
adUnitSizeStrings.add(String.format("{%s x %s}", updatedAdUnitSize.getSize().getWidth(),