Once you have beaten the first Gym Leader in Oreburgh, go down to the basement of the Pokémon Center. Teala, the attendant at the basement, will explain the Nintendo Wi-Fi Connection system and give you a Pal Pad. After connecting to the Nintendo Wi-Fi Connection for the first time, your Friend Code will be assigned to you, which you can see if you open the Pal Pad and choose the respective option.