Well, you need a wi-fi game first (Mario Kart DS, Animal Crossing: WW, Metroid Prime Hunters, Tetris DS, Tony Hawks', Lost Magic). The way you get your friend code in each game varies, but it is usually found around the Wi-Fi settings.
And you just ask your friend for their code.