private static final String MASTER_CREATIVE_ID = "INSERT_MASTER_CREATIVE_ID_HERE";
public static void runExample(DfpServices dfpServices, DfpSession session,
long masterCreativeId) throws Exception {
// Get the CreativeSetService.
CreativeSetServiceInterface creativeSetService =
dfpServices.get(session, CreativeSetServiceInterface.class);
// Create a statement to only select creative sets that have the
// given master creative.
StatementBuilder statementBuilder = new StatementBuilder()
.where("masterCreativeId = :masterCreativeId")
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
.withBindVariableValue("masterCreativeId", masterCreativeId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get creative sets by statement.
CreativeSetPage page =
creativeSetService.getCreativeSetsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CreativeSet creativeSet : page.getResults()) {